﻿using System.IO;
using Luna.Data;

namespace Luna.Model.Configuration
{
    internal class ConfigurationService : IConfigurationService
    {
        public ConfigurationService()
        {
        }

        private ApplicationStatus status = new ApplicationStatus();

        public IRepositoryManager Manager { get; set; }

        public IApplicationStatus Status
        {
            get { return status; }
        }

        public void New()
        {
            Manager.Create(Path.GetTempFileName() + ".mdf");

            status.CurrentFile = "Nouveau fichier";

            /*IConnectorData L_Data = DataContext.Create<IConnectorData>();
            L_Data.Login = "ycarpent@gmail.com";
            L_Data.Password = "28cyriletlea&";
            DataContext.Connectors[ConnectorType.Google].Configure(L_Data);*/
            //InitializeConnectors();

            // _ConnectorConfigurations[ConnectorType.Google].Login = "ycarpent@gmail.com";
            // _ConnectorConfigurations[ConnectorType.Google].Password = "28cyriletlea&";

            //OnDatabaseChanged(EventArgs.Empty);
        }

        public void Close()
        {
            Manager.Disconnect();
        }

        public void Open(string fileName)
        {
            // Open database
            Manager.Disconnect();
            Manager.Open(fileName);

            // InitializeConnectors();

            // Configure connectors
            /*foreach (var L_ConnectorConfiguration in DataContext.Configuration.GetAllConnectors())
            {
                var L_Connector = DataContext.Connectors[L_ConnectorConfiguration.Type];
                var L_Config = ConnectorConfiguration.Create(L_Connector, L_ConnectorConfiguration);
                L_Connector.Configure(L_Config);
                _ConnectorConfigurations[L_Config.Type] = L_Config;
            }*/

            // Set current database description
            status.CurrentFile = Path.GetFileNameWithoutExtension(fileName);
            // OnDatabaseChanged(EventArgs.Empty);
        }

        public void SaveAs(string fileName)
        {
            Manager.SaveAs(fileName);

            status.CurrentFile = Path.GetFileNameWithoutExtension(fileName);
        }
    }
}